<?php

namespace app\common\model;

use think\Db;
use think\Model;
use think\Validate;

/**
 * 作业表模型
 */
class HomeworkAssignmentImageRelation extends Model
{
    // 表名,不含前缀
    protected $name = 'homework_assignment_image_relation';

    /**
     * 列表
     */
    public function dataList($dis)
    {
        $res = $this->where([]);

        // 遍历条件数组，动态构建查询条件
        foreach ($dis as $field => $condition) {
            if (Validate::is($condition, 'array') && isset($condition[0]) && $condition[0] === 'in') {
                // 处理 IN 条件
                $res->whereIn($field, $condition[1]);
            } else {
                // 普通条件
                $res->where($field, $condition);
            }
        }

        return $res->select();
    }

    /**
     * 新增
     */
    public function dataAdd($data)
    {
        $res = $this->save($data);
        return $res;
    }
}